package com.telenav.ui;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;

public class AndroidDialog extends Dialog implements OnCancelListener
{
	private int id;
	private boolean visible;
	private Dialog dialog;
	protected IUiEventListener commandListener;
	
	public AndroidDialog(Context context, Dialog dialog) 
	{
		super(context);
		this.dialog = dialog;
		this.dialog.setOnCancelListener(this);
	}

	public int getId() 
	{
		return id;
	}

	public void setId(int id) 
	{
		this.id = id;
	}

	public boolean isVisible() 
	{
		return visible;
	}

	public void setVisible(boolean visible) 
	{
		this.visible = visible;
	}
	
    public final void setCommandEventListener(IUiEventListener commandListener)
    {
        this.commandListener = commandListener;
    }
	
	public Dialog getDialog()
	{
		return dialog;
	}
	
	@Override
	public void onCancel(DialogInterface paramDialogInterface) {
        UiEvent uiEvent = new UiEvent(UiEvent.TYPE_KEY_EVENT);
        uiEvent.setKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK));
		
		if(this.commandListener != null)
		{
			this.commandListener.handleUiEvent(uiEvent);
		}
		
	}

}
